#define fileupload(x)
		<div class="form-group" style="display:#(display??'block')">
			<div class="col-sm-10" id="_#(x.index??)_BTN">
				<label class="control-label no-padding-right" id="_#(x.index??)_upload" style="cursor:pointer;"><i class="fa fa-cloud-upload"></i>&nbsp;选择附件</label>			
				<input type="hidden" id="_#(x.index??)" data-type="fileupload" name="#(table??x.table).#(x.index??)"  value=""  class="form-control"/>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-12" id="_#(x.index??)_file">
			
			</div>
		</div>
		<div class="form-group" style="display:none;">
			<textarea  id="#(x.index??)_editor" name="#(x.index??)_editor" ></textarea>
		</div>
		
		<script charset="utf-8" src="/static/kindeditor/kindeditor-all.js"></script>
		<script type="text/javascript">
		function _#(x.index??)_loadfileupload(){
			var editor = KindEditor.create('textarea[name="#(x.index??)_editor"]', {
				uploadJson : '/kindeditor/upload',
				fileManagerJson : '/kindeditor/file_manager_json',
				allowFileManager : false,
				extraFileUploadParams : {dir:"#(x.dir)", uploadType : "#(x.uploadType)",typeCode:"#(x.typeCode)",attachId:"#(x.attachId)",table:"#(x.table)"},
				imageSizeLimit:'5MB'
			});
			KindEditor("#_#(x.index??)_upload").click(function () {
                editor.loadPlugin('insertfile', function () {
                    editor.plugin.fileDialog({
                        clickFn: function (url,title,fileId) {
        					var ids = $("#_#(x.index??)").val();
        					if(ids == ""){
        						ids = fileId;
        					}
        					else{
            					ids += "," + fileId;
        					}
        					$("#_#(x.index??)").val(ids);
                            $("#_#(x.index??)_file").append(_#(x.index??)_getFile(url, fileId, title));
                            $("#form_token").val(1); 
                            editor.hideDialog();
                        }
                    });
                });
            });
		}
		
			function _#(x.index??)_initFileUpload(ids, type){
				_#(x.index??)_loadmultiimgupload();
				$.ajax({
			        type: "post",
			        url: "/kindeditor/initfile",
			        dataType: "json",
			        async: false,
			        data: {ids : ids},
			        success: function(data) {
			        	if(data.state == 'ok'){
							var file = data.data;
							for(var x = 0; x < file.length; x++){
								var id = file[x].id;
								var name = file[x].name;
								var url = "/kindeditor/renderFile/" + id;
								if(type == "edit"){
									$("#_#(x.index??)_file").append(_#(x.index??)_getFile(url, id, name));
								}
								else{
									$("#_#(x.index??)_BTN").css("display", "none");
									$("#_#(x.index??)_file").append(_#(x.index??)_getViewFile(url, id, name));
								}
								
							}
						}
						else{
							layer.alert("加载附件失败", {
								icon : 7
							});
						}
			        }
			    });
			}
			
			function _#(x.index??)_getFile(url, id, name){
				var html = [];
				html.push('<div class="alert alert-block alert-success" id="_#(x.index??)_file_' + id + '">');
				html.push("	<button type=\"button\" class=\"close\" onclick=\"_#(x.index??)_deleteFile(" + id + ",'" + name + "')\">");
				html.push('		<i class="ace-icon fa fa-times"></i>');
				html.push('	</button>');
				html.push('	<i class="ace-icon fa fa-cloud-download green"></i>');
				html.push('	<strong class="green">');
				html.push('		<a class="green" href="'+url+'" target="_blank">' + name + '</a>');
				html.push('	</strong>');
				html.push('</div>');
				return html.join('');
			}
			
// 			function _#(x.index??)_getViewFile(url, id, name){
// 				var html = [];
// 				html.push('<div class="alert alert-block alert-success" id="#(x.index??)_file_' + id + '">');
// 				html.push('	<i class="ace-icon fa fa-cloud-download green"></i>');
// 				html.push('	<strong class="green">');
// 				html.push('		<a class="green" href="'+url+'" target="_blank">' + name + '</a>');
// 				html.push('	</strong>');
// 				html.push('</div>');
// 				return html.join('');
// 			}
			
			function _#(x.index??)_deleteFile(id, name){
				 layer.confirm('是否删除选中文件 (' + name + ') ？', {
		                icon: 3,
		                btn: ['确定', '取消']
		            }, function () {
		            	$("#_#(x.index??)_file_" + id).remove();
		           		var ids = $("#_#(x.index??)").val();
		           		
		           		var idArr = ids.split(",");
		           		if(_contains(idArr, id)){
		           			idArr.remove(id);
		           		}
		           		
						var newids = idArr.join(",");
		           		$("#_#(x.index??)").val(newids);
		           	 	$("#form_token").val(1);
		           		layer.msg("删除成功!", {icon:1});
		            }, function () {
		            });
			}
			
			function _contains(arr, obj){
				for (var i = 0; i < arr.length; i++) {
			        if (obj == arr[i] || obj.toString() == arr[i]) {
			            return true;
			        }
			    }
			    return false;
			}
			
		</script>
#end